package com.sgy.spring_ioc_xml.servlet;

import com.sgy.spring_ioc_xml.factory.ProxyFactory;
import com.sgy.spring_ioc_xml.pojo.Result;
import com.sgy.spring_ioc_xml.service.TransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Administrator
 * @date 2025/7/13 11:59
 * @description
 */
@RestController
public class TransferServlet {

    // 从beanfactory获取到proxyfactory代理工厂的实例化对象
    @Autowired
    private ProxyFactory proxyFactory;
    @Autowired
    private TransferService transferService;



    @RequestMapping("/transferServlet")
    public Result doPost(@RequestParam("fromCardNo") String fromCardNo, @RequestParam("toCardNo") String toCardNo, @RequestParam("money") Integer money){
        Result result = new Result();

        try {
            transferService = (TransferService) proxyFactory.getJdkProxy(transferService);
            transferService.transfer(fromCardNo,toCardNo,money);
            result.setStatus("200");
        } catch (Exception e) {
            e.printStackTrace();
            result.setStatus("201");
            result.setMessage(e.toString());
        }
        return result;
    }
}
